import * as API from '../axios'
import * as util from "@/common/util";

export default {

    createModify: (params) => {
        const url = '/manage/sys-users'
        const headers = {
            'lang-key': params.id ? 'branch_Edit' : 'branch_Create'
        }
        if (params.id) {
            return API.axiosPutAPI(url, params, headers)
        } else {
            return API.axiosPostAPI(url, params, headers)
        }
    },

    getPage: (params, page) => {
        const url = util.replacePageNumAndSize('/manage/sys-users/{pageNum}/{pageSize}', page)
        return API.axiosGetAPI(url, params)
    },

    getList: (params) => {
        return API.axiosGetAPI(`/manage/sys-users/${params.pageNum}/${params.pageSize}`, params)
    },

    getDetail: (id) => {
        return API.axiosGetAPI(`/manage/sys-users/${id}`)
    },

    // 获取用户角色列表
    getRoleList: () => {
        return API.axiosGetAPI('/manage/sys-users/roles')
    },

    // 冻结-解冻
    modifyState: (params) => {
        const headers = {
            'lang-key': params.state == 1 ? 'Account_unfreeze' : 'Users_Status_Dropdown_Freeze'
        }
        return API.axiosPutAPI(`/manage/sys-users/${params.id}/state?state=${params.state}`, null, headers)
    },

    // 重置密码
    resetPwd: (id, pwd) => {
        const headers = {
            'lang-key': 'Account_resetPasswords'
        }
        return API.axiosPutAPI(`/manage/sys-users/${id}/reset-password?password=${pwd}`, null, headers)
    },

    // 检查手机号是否存在
    checkPhone: params => {
        return API.axiosGetAPI(`/manage/sys-users/${params}/exists`)
    },

    // 获取账号信息
    getUserInfo: () => {
        return API.axiosGetAPI('/manage/sys-users/account')
    },

    //修改登入账号
    modifyLoginAccount: params => {
        return API.axiosPutAPI('/manage/sys-users/account/change', params)
    },
    //修改手机号
    modifyPhone: params => {
        return API.axiosPutAPI('/manage/sys-users/contact-phone', params)
    },
    //修改邮箱
    modifyEmail: params => {
        return API.axiosPutAPI('/manage/sys-users/contact-email', params)
    },
    //修改密码
    modifyPassword: params => {
        return API.axiosPutAPI('/manage/sys-users/change-password', params)
    },


    //修改时区
    modifyTimezone: params => {
        return API.axiosPutAPI('/manage/sys-users/timezone', params)
    },


    //获取登录设备
    getLoginDeviceList: params => {
        return API.axiosGetAPI('/manage/sys-users/login/device', params)
    },
    //登录设备-退出
    logoutDevice: id => {
        return API.axiosDeleteAPI(`/manage/sys-users/login/device/${id}`)
    },

    //系统角色-删除
    deleteSysRoles: (id) => {
        const headers = {
            'lang-key': 'delete'
        }
        return API.axiosDeleteAPI(`/manage/sys-roles/${id}`, '', headers);
    },

    //系统角色-更换所有用户的角色
    changeSysUser: (roleId, params) => {
        return API.axiosPutAPI(`/manage/sys-roles/${roleId}/user/all`, params);
    },
}